package com.action.member;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.controller.Action;
import com.dao.BookDao;
import com.dao.RentalDao;
import com.domain.Book;
import com.domain.Rental;

public class MyRentalAction implements Action{
	@Override
	public String execute(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		String mem_id  = request.getParameter("mem_id");
		RentalDao dao = RentalDao.getInstance();
		BookDao bookDao = BookDao.getinstance();
		List<Rental> rentals = new ArrayList<Rental>();
		rentals = dao.getMemberRental(mem_id);
		int size = rentals.size()-1;
		
		List<String> bookNames = new ArrayList<String>();
		
		for(int i = 0 ; i <rentals.size(); i++){
			Book book = bookDao.getBookByNum(rentals.get(i).getBook_num());
			bookNames.add(book.getBook_name());
		}
		
		request.setAttribute("mem_id", mem_id);
		request.setAttribute("rentals", rentals);
		request.setAttribute("bookNames", bookNames);
		request.setAttribute("size", size);
		
		return "/view/member/myRental.jsp";
	}
}
